<?php

class Site_PhotoController extends Fengqiaoju_Controller_Action {

	public function init() {

		parent::init ();
		$this->view->site_id = $this->site_id = $this->_request->getParam ( 'site_id' );
		$this->site_seo_name = $this->_request->getParam ( 'site_seo_name' );
		$this->view->model_id = $this->_request->getParam ( 'model_id' );
		$this->view->article_id = $this->_request->getParam ( 'photo_id' );
		$this->view->page_id = $this->_request->getParam ( 'page_id' );
		$this->view->photo_id = $this->_request->getParam ( 'id' );
		$this->view->page_id = $this->view->page_id ? $this->view->page_id : $this->view->photo_id;
	}

	public function indexAction() {

		$modelObject = new Site_Models_Model ();
		$photoObject = new Site_Models_Photo ();
		$siteObject = new Site_Models_Site ();
		
		$numPerPage = 10;
		$page = $this->view->page_id ? $this->view->page_id : 1;
		$offset = $numPerPage * intval($page-1);
		
		//当前模块信息
		$where = array ();
		$where = "model_id=" . intval ( $this->view->model_id );
		$this->view->modelInfo = $modelObject->fetchRow ( $where );
		
		if (! $this->view->modelInfo ['model_id']) {
			$this->message ( '您访问的模块不存在' );
		}
		
		//头部导航菜单
		$where = array ();
		$where = 'site_id = ' . intval ( $this->view->modelInfo ['site_id'] );
		$this->view->modelList = $modelObject->fetchAll ( $where );
		
		//小站信息
		$where = array ();
		$where = "site_id=" . intval ( $this->view->modelInfo ['site_id'] );
		$this->view->siteInfo = $siteObject->fetchRow ( $where );
		
		//页面内容
		$where = array ();
		$where = "model_id=" . intval ( $this->view->model_id );
		$this->view->photoInfo = $photoObject->fetchRow ( $where );
		
		//页面列表
		$where = '';
		$where = 'model_id = ' . intval ( $this->view->photoInfo ['model_id'] );
		$this->view->photoList = $photoObject->fetchAll ( $where, 'photo_id DESC', $numPerPage, $offset );
		
		$this->view->title = $this->view->modelInfo ['model_name'] . '_' . $this->view->siteInfo ['site_name'] . "-" . $this->config ['site'] ['title'];
		$this->view->keywords = $this->view->modelInfo ['model_name'] . ',' . $this->view->siteInfo ['site_name'] . "," . $this->view->modelInfo ['model_name'] . "的照片";
		$this->view->description = $this->view->siteInfo ['site_name'] . "的" . $this->view->modelInfo ['model_name'] . '模块' . "," . $this->view->modelInfo ['model_name'] . "照片." . strip_tags ( $this->view->modelInfo ['model_intro'] ) . "-" . $this->config ['site'] ['title'];
		
		$paginator = Zend_Paginator::factory ( $photoObject->fetchAll ( $where ) );
		$paginator->setCurrentPageNumber ( $page )->setItemCountPerPage ( $numPerPage );
		$this->view->paginator = $paginator;
	}

	/**
	 * 显示照片
	 */
	public function showAction() {

		$modelObject = new Site_Models_Model ();
		$photoObject = new Site_Models_Photo ();
		$siteObject = new Site_Models_Site ();
		
		//当前模块信息
		$where = '';
		$where = "model_id=" . intval ( $this->view->model_id );
		$this->view->modelInfo = $modelObject->fetchRow ( $where );
		
		//头部导航菜单
		$where = '';
		$where = 'site_id = ' . intval ( $this->view->modelInfo ['site_id'] );
		$this->view->modelList = $modelObject->fetchAll ( $where );
		
		//小站信息
		$where = '';
		$where = "site_id=" . intval ( $this->view->modelInfo ['site_id'] );
		$this->view->siteInfo = $siteObject->fetchRow ( $where );
		
		//照片信息
		$where = '';
		$where = 'photo_id =' . intval ( $this->view->photo_id );
		$this->view->photoInfo = $photoObject->fetchRow ( $where );
		
		//上一页
		$where = '';
		$where = 'photo_id<' . $this->view->photoInfo ['photo_id'] . " AND model_id=" . intval ( $this->view->photoInfo ['model_id'] );
		$this->view->pre = $photoObject->fetchRow ( $where, 'photo_id DESC' );
		
		//下一页
		$where = '';
		$where = 'photo_id>' . $this->view->photoInfo ['photo_id'] . " AND model_id=" . intval ( $this->view->photoInfo ['model_id'] );
		$this->view->next = $photoObject->fetchRow ( $where, 'photo_id ASC' );
			
		//第一页
		$where = '';
		$where =   "  model_id=" . intval ( $this->view->photoInfo ['model_id'] );
		$this->view->first = $photoObject->fetchRow ( $where, 'photo_id ASC' );
		
		//照片评论
		$this->commentObject = new Site_Models_Comment ();
		$this->view->userObject = $this->userObject;
		$where = "model_type='photo' AND item_id=" . intval ( $this->view->photoInfo ['photo_id'] );
		$this->view->comment = $this->commentObject->fetchAll ( $where, 'comment_inputtime DESC', 20, 0 );
		
		$this->view->title = $this->view->photoInfo ['photo_name'] . '_' . $this->view->modelInfo ['model_name'] . '_' . $this->view->siteInfo ['site_name'] . "-" . $this->config ['site'] ['title'];
		$this->view->keywords = $this->view->photoInfo ['photo_name'] . ',' . $this->view->photoInfo ['photo_name'] . '图片,' . $this->view->modelInfo ['model_name'] . ',' . $this->view->siteInfo ['site_name'];
		$this->view->description = "关于" . $this->view->siteInfo ['site_name'] . '小站' . $this->view->modelInfo ['model_name'] . $this->view->photoInfo ['photo_name'] . '图片信息,' . $this->view->photoInfo ['photo_name'] . '相册,' . $this->view->modelInfo ['model_name'] . "信息";
	
	}
}